<template>
	<view class="container">
		<!-- 顶部安全区域占位 -->
		<!-- <view class="status-bar"></view> -->

		<!-- 顶部导航栏 -->
		<!-- 		<uni-nav-bar left-icon="left" title="维修任务详情" backgroundColor="#2a8cff" color="#fff" @clickLeft="goBack" /> -->

		<!-- 主要内容区域 -->
		<view class="content">
			<!-- 任务状态卡片 -->
			<view class="status-card">
				<view class="status-header">
					<view class="status-icon" :class="isArrived ? 'arrived' : 'pending'">
						<uni-icons :type="isArrived ? 'checkmarkempty' : 'clock'" size="24"
							:color="isArrived ? '#52c41a' : '#faad14'"></uni-icons>
					</view>
					<view class="status-info">
						<text class="status-text">{{ isArrived ? '已到场' : '待到场' }}</text>
						<text class="status-desc">{{ isArrived ? '客户已确认到场' : '等待客户到场确认' }}</text>
					</view>
				</view>
				<view class="task-number-section">
					<text class="number-label">维修单号</text>
					<text class="number-value">3535252</text>
				</view>
			</view>

			<!-- 维修信息卡片 -->
			<view class="info-card">
				<view class="card-header">
					<uni-icons type="gear" size="20" color="#2a8cff"></uni-icons>
					<text class="card-title">维修信息</text>
				</view>
				<view class="info-list">
					<view class="info-item">
						<view class="info-row">
							<uni-icons type="person" size="16" color="#999"></uni-icons>
							<text class="info-label">车主姓名</text>
						</view>
						<text class="info-value">张先生</text>
					</view>
					<view class="info-item with-action">
						<view class="info-row">
							<uni-icons type="phone" size="16" color="#999"></uni-icons>
							<text class="info-label">联系方式</text>
						</view>
						<view class="info-value-section">
							<text class="info-value">1993829282</text>
							<button class="action-btn phone-btn" @click="makeCall">
								<uni-icons type="phone" size="14" color="#fff"></uni-icons>
							</button>
						</view>
					</view>
					<view class="info-item">
						<view class="info-row">
							<uni-icons type="car" size="16" color="#999"></uni-icons>
							<text class="info-label">维修方式</text>
						</view>
						<view class="repair-type-badge">
							<text>上门取车 / 到店维修</text>
						</view>
					</view>
					<view class="info-item with-action">
						<view class="info-row">
							<uni-icons type="location" size="16" color="#999"></uni-icons>
							<text class="info-label">取车位置</text>
						</view>
						<view class="info-value-section">
							<text class="info-value">山阳区32号</text>
							<button class="action-btn location-btn" @click="showLocation">
								<uni-icons type="location" size="14" color="#fff"></uni-icons>
							</button>
						</view>
					</view>
					<view class="info-item">
						<view class="info-row">
							<uni-icons type="calendar" size="16" color="#999"></uni-icons>
							<text class="info-label">预约日期</text>
						</view>
						<text class="info-value">2022/11/10 11:00</text>
					</view>
					<view class="info-item">
						<view class="info-row">
							<uni-icons type="clock" size="16" color="#999"></uni-icons>
							<text class="info-label">提交日期</text>
						</view>
						<text class="info-value">2022/11/08 12:34</text>
					</view>
					<view class="info-item" v-if="isArrived">
						<view class="info-row">
							<uni-icons type="checkmarkempty" size="16" color="#999"></uni-icons>
							<text class="info-label">到场时间</text>
						</view>
						<text class="info-value arrived-time">{{ arrivalTime }}</text>
					</view>
					<view class="info-item" v-else>
						<view class="info-row">
							<uni-icons type="clock" size="16" color="#999"></uni-icons>
							<text class="info-label">到场时间</text>
						</view>
						<text class="info-value not-arrived">未到场</text>
					</view>
				</view>
			</view>

			<!-- 车辆信息卡片 -->
			<view class="info-card">
				<view class="card-header">
					<uni-icons type="car" size="20" color="#2a8cff"></uni-icons>
					<text class="card-title">车辆信息</text>
				</view>
				<view class="vehicle-info">
					<view class="vehicle-basic">
						<view class="vehicle-item">
							<text class="vehicle-label">车辆类型</text>
							<text class="vehicle-value">大客车</text>
						</view>
						<view class="vehicle-item">
							<text class="vehicle-label">车牌号</text>
							<text class="vehicle-value">豫J45323</text>
						</view>
					</view>

					<view class="photo-section">
						<text class="photo-title">整车照片</text>
						<view class="photo-container">
							<image src="https://picsum.photos/200/300" class="car-photo" mode="widthFix" alt="整车照片">
							</image>
						</view>
					</view>

					<view class="photo-section">
						<text class="photo-title">维修部位照片</text>
						<view class="photos-container">
							<image src="https://picsum.photos/200/300?1" class="repair-photo" mode="widthFix"
								alt="维修部位照片1"></image>
							<image src="https://picsum.photos/200/300?2" class="repair-photo" mode="widthFix"
								alt="维修部位照片2"></image>
							<image src="https://picsum.photos/200/300?3" class="repair-photo" mode="widthFix"
								alt="维修部位照片3"></image>
						</view>
					</view>
				</view>
			</view>
		</view>

		<!-- 确认到场按钮 -->
		<view class="button-container">
			<button class="confirm-btn" @click="confirmArrival" v-if="!isArrived">
				<uni-icons type="checkmarkempty" size="18" color="#fff"></uni-icons>
				<text>确认到场</text>
			</button>
			<button class="arrived-btn" disabled v-else>
				<uni-icons type="checkmarkempty" size="18" color="#52c41a"></uni-icons>
				<text>已到场</text>
			</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 可以从路由参数中获取订单号
				orderNo: '',
				// 到场状态
				isArrived: false,
				// 到场时间
				arrivalTime: ''
			};
		},
		onLoad(options) {
			// 接收传递的订单号
			if (options.orderNo) {
				this.orderNo = options.orderNo;
			}
		},
		methods: {
			// 返回上一页
			goBack() {
				uni.navigateBack();
			},
			// 拨打电话
			makeCall() {
				uni.makePhoneCall({
					phoneNumber: '1993829282'
				});
			},
			// 查看位置
			showLocation() {
				uni.showToast({
					title: '显示位置地图',
					icon: 'none'
				});
				// 这里可以添加打开地图的逻辑
			},
			// 确认到场
			confirmArrival() {
				uni.showModal({
					title: '确认到场',
					content: '确认客户已到场？',
					success: (res) => {
						if (res.confirm) {
							// 执行到场确认操作
							this.processArrival();
						}
					}
				});
			},
			// 处理到场确认
			processArrival() {
				// 模拟到场确认过程
				setTimeout(() => {
					// 更新到场状态
					this.isArrived = true;

					// 记录到场时间
					const date = new Date();
					this.arrivalTime = date.toLocaleString('zh-CN', {
						year: 'numeric',
						month: '2-digit',
						day: '2-digit',
						hour: '2-digit',
						minute: '2-digit',
						second: '2-digit',
						hour12: false
					}).replace(/\//g, '-');

					// 显示确认成功提示
					uni.showToast({
						title: '确认到场成功',
						icon: 'success',
						duration: 2000
					});
				}, 1000);
			}
		}
	};
</script>

<style>
	.container {
		background: linear-gradient(135deg, #2a8cff 0%, #764ba2 100%);
		min-height: 100vh;
		display: flex;
		flex-direction: column;
	}

	/* 顶部安全区域 */
	.status-bar {
		height: var(--status-bar-height);
		background: linear-gradient(135deg, #2a8cff 0%, #764ba2 100%);
	}

	/* 主要内容区域 */
	.content {
		flex: 1;
		padding: 20rpx;
	}

	/* 状态卡片 */
	.status-card {
		background-color: #fff;
		border-radius: 20rpx;
		padding: 30rpx;
		margin-bottom: 20rpx;
		box-shadow: 0 8rpx 32rpx rgba(0, 0, 0, 0.1);
	}

	.status-header {
		display: flex;
		align-items: center;
		margin-bottom: 25rpx;
	}

	.status-icon {
		width: 60rpx;
		height: 60rpx;
		border-radius: 50%;
		display: flex;
		align-items: center;
		justify-content: center;
		margin-right: 20rpx;
	}

	.status-icon.arrived {
		background: linear-gradient(135deg, #52c41a 0%, #73d13d 100%);
	}

	.status-icon.pending {
		background: linear-gradient(135deg, #faad14 0%, #ffc53d 100%);
	}

	.status-info {
		flex: 1;
	}

	.status-text {
		font-size: 32rpx;
		font-weight: 600;
		color: #333;
		display: block;
		margin-bottom: 8rpx;
	}

	.status-desc {
		font-size: 24rpx;
		color: #666;
	}

	.task-number-section {
		background: linear-gradient(135deg, #f0f2ff 0%, #e6f7ff 100%);
		border-radius: 12rpx;
		padding: 20rpx;
		text-align: center;
	}

	.number-label {
		font-size: 24rpx;
		color: #666;
		display: block;
		margin-bottom: 10rpx;
	}

	.number-value {
		font-size: 36rpx;
		color: #2a8cff;
		font-weight: 600;
		letter-spacing: 2rpx;
		font-family: 'Courier New', monospace;
	}

	/* 信息卡片 */
	.info-card {
		background-color: #fff;
		border-radius: 20rpx;
		padding: 30rpx;
		margin-bottom: 20rpx;
		box-shadow: 0 8rpx 32rpx rgba(0, 0, 0, 0.1);
	}

	.card-header {
		display: flex;
		align-items: center;
		margin-bottom: 25rpx;
		padding-bottom: 15rpx;
		border-bottom: 1px solid #f0f0f0;
	}

	.card-title {
		font-size: 30rpx;
		font-weight: 600;
		color: #333;
		margin-left: 12rpx;
	}

	/* 信息列表 */
	.info-list {
		width: 100%;
	}

	/* 信息项 */
	.info-item {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 18rpx 0;
		border-bottom: 1px solid #f5f5f5;
	}

	.info-item:last-child {
		border-bottom: none;
	}

	.info-row {
		display: flex;
		align-items: center;
		flex: 1;
	}

	.info-label {
		font-size: 26rpx;
		color: #666;
		margin-left: 12rpx;
	}

	.info-value {
		font-size: 26rpx;
		color: #333;
		font-weight: 500;
	}

	.info-value-section {
		display: flex;
		align-items: center;
		gap: 15rpx;
	}

	/* 操作按钮 */
	.action-btn {
		width: 60rpx;
		height: 60rpx;
		border-radius: 50%;
		display: flex;
		align-items: center;
		justify-content: center;
		transition: all 0.3s ease;
	}

	.phone-btn {
		background: linear-gradient(135deg, #52c41a 0%, #73d13d 100%);
		box-shadow: 0 4rpx 16rpx rgba(82, 196, 26, 0.3);
	}

	.location-btn {
		background: linear-gradient(135deg, #1890ff 0%, #40a9ff 100%);
		box-shadow: 0 4rpx 16rpx rgba(24, 144, 255, 0.3);
	}

	.action-btn:active {
		transform: scale(0.95);
	}

	/* 维修方式标签 */
	.repair-type-badge {
		background: linear-gradient(135deg, #2a8cff 0%, #764ba2 100%);
		color: #fff;
		padding: 8rpx 16rpx;
		border-radius: 16rpx;
		font-size: 24rpx;
		font-weight: 500;
	}

	/* 特殊样式 */
	.arrived-time {
		color: #52c41a;
		font-weight: 500;
	}

	.not-arrived {
		color: #999;
	}

	/* 车辆信息 */
	.vehicle-info {
		/* 车辆信息样式 */
	}

	.vehicle-basic {
		display: flex;
		gap: 30rpx;
		margin-bottom: 25rpx;
	}

	.vehicle-item {
		flex: 1;
		background: linear-gradient(135deg, #f6f8ff 0%, #f0f2ff 100%);
		padding: 20rpx;
		border-radius: 12rpx;
		text-align: center;
	}

	.vehicle-label {
		font-size: 24rpx;
		color: #666;
		display: block;
		margin-bottom: 8rpx;
	}

	.vehicle-value {
		font-size: 28rpx;
		color: #333;
		font-weight: 500;
	}

	/* 照片区域 */
	.photo-section {
		margin-bottom: 25rpx;
	}

	.photo-section:last-child {
		margin-bottom: 0;
	}

	.photo-title {
		font-size: 26rpx;
		color: #666;
		display: block;
		margin-bottom: 15rpx;
	}

	.photo-container {
		width: 100%;
		text-align: center;
	}

	.car-photo {
		width: 300rpx;
		height: 200rpx;
		border-radius: 12rpx;
		object-fit: cover;
		box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.1);
	}

	.photos-container {
		display: flex;
		gap: 15rpx;
		justify-content: center;
	}

	.repair-photo {
		width: 150rpx;
		height: 150rpx;
		border-radius: 12rpx;
		object-fit: cover;
		box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.1);
	}

	/* 按钮容器 */
	.button-container {
		padding: 20rpx 20rpx 50rpx;
	}

	/* 确认到场按钮 */
	.confirm-btn {
		width: 100%;
		background: linear-gradient(135deg, #2a8cff 0%, #764ba2 100%);
		color: #fff;
		font-size: 32rpx;
		padding: 25rpx 0;
		border-radius: 25rpx;
		box-shadow: 0 8rpx 32rpx rgba(102, 126, 234, 0.3);
		transition: all 0.3s ease;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.confirm-btn text {
		margin-left: 12rpx;
	}

	.confirm-btn:active {
		transform: translateY(2rpx);
		box-shadow: 0 4rpx 16rpx rgba(102, 126, 234, 0.4);
	}

	/* 已到场按钮 */
	.arrived-btn {
		width: 100%;
		background: linear-gradient(135deg, #f0f0f0 0%, #e8e8e8 100%);
		color: #999;
		font-size: 32rpx;
		padding: 25rpx 0;
		border-radius: 25rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.arrived-btn text {
		margin-left: 12rpx;
	}
</style>